<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const fn1 = function (n1, n2) {
      console.log(n1, n2);
      console.log(this);
    }
    const lisi = {
      name: 'lisi',
    }
    // fn1(1,2)

    // call
    // fn1.call(lisi, 1, 2)
    //apply
    // fn1.apply(lisi, [1, 2])

    //bind --- 需要手动调用原函数
    fn1.bind(lisi, 1, 2)()



    // const wangwu = {
    //   name: 'wangwu',
    //   eat() {
    //     console.log(this);// wangwu
    //     setTimeout(function () {  //回调函数
    //       console.log(this);//window == 》 wangwu
    //     }.bind(wangwu), 2000);
    //   }
    // }
    const wangwu = {
      name: 'wangwu',
      eat() {
        console.log(this);// wangwu
        setTimeout(() => {  //回调函数
          console.log(this);//window == 》 wangwu
        }, 2000)
      },
      sleep: () => {
        console.log(this);
      }
    }
    // wangwu.eat()
    wangwu.sleep()


  </script>
</body>

</html>